home *** CD-ROM | disk | FTP | other *** search
/ Run Magazine ReRun 1985 Fall / rerun-1985-fall.d64 / micro compiler (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  6KB  |  237 lines

  1. 10 print"[153]micro compiler"
  2. 15 rem by vic cortes
  3. 20 gosub1780:goto590
  4. 30 rem .. first var
  5. 40 gosub400:pokea,169:pokea+1,l:k=2
  6. 50 ifvthenpokea,173:pokea+2,h:k=3
  7. 60 a=a+k:pokea,174:pokea+1,c:pokea+2,h
  8. 70 ifv=0thenpokea,162:pokea+1,h
  9. 80 a=a+k:return
  10. 90 rem .. expr
  11. 100 p=0:ifpeek(u)=194thenu=u+2:p=1
  12. 110 gosub40
  13. 120 ifu>912thenprint"overflow2":return
  14. 130 o=0:b=peek(u):ifb=173then280
  15. 140 ifb=172then280
  16. 150 ifb=170theno=109:pokea,24:a=a+1
  17. 160 ifb=171theno=237:pokea,56:a=a+1
  18. 170 ifb=175theno=45
  19. 180 ifb=176theno=13
  20. 190 ifo=0then320
  21. 200 u=u+1:gosub400:pokea,o-4:pokea+1,l:k=2
  22. 210 ifvthenpokea,o:pokea+2,h:k=3
  23. 220 a=a+k:pokea,168:pokea+1,138:a=a+2
  24. 230 pokea,o:pokea+1,c:pokea+2,h
  25. 240 ifv=0thenpokea,o-4:pokea+1,h
  26. 250 a=a+k:pokea,170:pokea+1,152:a=a+2
  27. 260 goto120
  28. 270 rem .. mul/div
  29. 280 pokea,133:pokea+1,97:pokea+2,134:pokea+3,98:a=a+4:u=u+1:gosub40
  30. 290 g=1:pokea,24:ifb=173thenpokea,56
  31. 300 d=s+3:gosub570:pokea+1,32:pokea+2,l:pokea+3,h:a=a+4:goto120
  32. 310 rem .. peek(expr)
  33. 320 ifp=0thenreturn
  34. 330 pokea,133:pokea+1,34
  35. 340 pokea+2,134:pokea+3,35
  36. 350 pokea+4,162:pokea+5,0
  37. 360 pokea+6,160:pokea+7,0
  38. 370 pokea+8,177:pokea+9,34
  39. 380 a=a+10:u=u+1:p=0:goto120
  40. 390 rem .. find
  41. 400 n=0:v=0:ifpeek(u)<65then420
  42. 410 ifpeek(u)<91then490
  43. 420 t=0:ifpeek(u)=170thenu=u+1:goto450
  44. 430 ifpeek(u)=171thenu=u+1:t=1
  45. 440 ifpeek(u)<48orpeek(u)>57thenprint"**error at pos";u-827;peek(u)
  46. 450 ifpeek(u)>47andpeek(u)<58thenn=n*10+peek(u)-48:u=u+1:goto450
  47. 460 ift=0thend=n:goto570
  48. 470 d=65536-n:goto570
  49. 480 rem .. h/l
  50. 490 v=peek(u):d=v
  51. 500 u=u+1:t=peek(u):ift>90then560
  52. 510 ift<32then560
  53. 520 ift=59then560
  54. 530 ift=44then560
  55. 540 ift=41then560
  56. 550 ift>35then500
  57. 560 d=d-65:d=d+d+680
  58. 570 h%=d/256:h=h%:l=d-h*256:c=(l+1)and255:return
  59. 580 rem .. read source       
  60. 590 get#2,a1$,a2$:ti$="000000"
  61. 600 get#2,l1$,l2$:t=asc(l1$+z$)+asc(l2$+z$):ift=0then1920
  62. 610 get#2,s1$,s2$:t=asc(s1$+z$)+asc(s2$+z$)*256
  63. 620 s(m)=t:l(m)=a:m=m+1:print"[157]";t;
  64. 630 iffthent=a-f:pokef+1,t-2:pokef+7,t-8:pokef+9,t-10:f=0
  65. 640 j=828:ifpeek(653)then640
  66. 650 get#2,b$:ifstthen1920
  67. 660 b=asc(b$+z$):pokej,b:ifqorb<>32thenj=j+1
  68. 670 ifb=34thenq=notq
  69. 680 ifb<128orqthenprintb$;
  70. 690 poke780,b:poke15,0
  71. 700 ifb>127andb<204andq=0thenpoke782,255:poke768,185:sys42775
  72. 710 poke768,139:ifqthen650
  73. 720 ifb<32thenprint:gosub770:goto600
  74. 730 ifb=167thengosub770:goto640
  75. 740 ifb=58thenj=j-1:gosub770:goto640
  76. 750 goto650
  77. 760 rem .. process
  78. 770 b=peek(828):u=829:pokej,0:pokej+1,0
  79. 780 ifb=136then940
  80. 790 ifb=128orb=142orb=144thenpokea,96:a=a+1:return
  81. 800 ifb=158then1680
  82. 810 ifb=139then1040
  83. 820 ifb=153then1170
  84. 830 ifb=151then1720
  85. 840 ifb=129then1510
  86. 850 ifb=130then1650
  87. 860 ifb=143thenreturn
  88. 870 ifb=137theno=76:goto1480
  89. 880 ifb=141theno=32:goto1480
  90. 890 ifb<48orb>90then920
  91. 900 ifb>64then950
  92. 910 ifb<58thenu=828:o=76:goto1480
  93. 920 print"error";u-827:er=er+1:return
  94. 930 rem .. v=expr
  95. 940 fori=828to842:pokei,peek(i+1):next
  96. 950 u=828:ifpeek(u)<65then920
  97. 960 ifpeek(u)>90then920
  98. 970 u=u+1:ifpeek(u)<>178then920
  99. 980 u=u+1:gosub100:d=peek(828)
  100. 990 gosub560
  101. 1000 pokea,141:pokea+1,l:pokea+2,h
  102. 1010 pokea+3,142:pokea+4,c:pokea+5,h
  103. 1020 a=a+6:return
  104. 1030 rem .. if/then
  105. 1040 gosub100:w=peek(u):ifw<177then920
  106. 1050 ifw>179then920
  107. 1060 pokea+0,133:pokea+1,34:pokea+2,134:pokea+3,35:a=a+4:u=u+1
  108. 1070 ifw=179andpeek(u)=177thenw=180:u=u+1
  109. 1080 ifw=177andpeek(u)=179thenw=180:u=u+
  110. 1090 gosub100:pokea,228:pokea+1,35:pokea+2,240:pokea+3,4:a=a+4:f=a
  111. 1100 pokea+3,6:pokea+4,197:pokea+5,34
  112. 1110 pokea,240:pokea+2,208:pokea+8,240
  113. 1120 ifw=178thenpokea,208:pokea+8,208
  114. 1130 ifw=179thenpokea,144:pokea+2,176
  115. 1140 ifw=177thenpokea,176:pokea+2,144
  116. 1150 pokea+6,peek(a):a=a+10:return
  117. 1160 rem .. print      
  118. 1170 w=peek(u):ifw<32then1450
  119. 1180 ifw=59andpeek(u+1)<32thenreturn
  120. 1190 ifw=59thenu=u+1:goto1170
  121. 1200 ifw=199then1300:rem chr$
  122. 1210 ifw=34then1340:rem"string"
  123. 1220 rem .. print expr
  124. 1230 pokea,169:pokea+1,29:pokea+2,32
  125. 1240 pokea+3,210:pokea+4,255:a=a+5
  126. 1250 gosub100:pokea,134:pokea+1,34
  127. 1260 pokea+2,170:pokea+3,165:pokea+4,34
  128. 1270 pokea+5,32:pokea+6,205:pokea+7,189
  129. 1280 a=a+8:goto1170
  130. 1290 rem .. print chr$(expr)
  131. 1300 u=u+1:ifpeek(u)<>40then920
  132. 1310 u=u+1:gosub100:pokea,32:pokea+1,210
  133. 1320 pokea+2,255:a=a+3:u=u+1:goto1170
  134. 1330 rem .. print "str"
  135. 1340 d=a+10:gosub570:pokea,169
  136. 1350 pokea+1,l:pokea+2,160:pokea+3,h
  137. 1360 pokea+4,32:pokea+5,30:pokea+6,171
  138. 1370 pokea+7,24:pokea+8,144:pokea+9,0
  139. 1380 w=a+9:a=a+10:i=0
  140. 1390 i=i+1:u=u+1:ifu>912then1430
  141. 1400 ifpeek(u)=34then1430
  142. 1410 ifpeek(u)=0then1430
  143. 1420 pokea,peek(u):a=a+1:goto1390
  144. 1430 pokew,i:pokea,0:a=a+1
  145. 1440 u=u+1:goto1170
  146. 1450 pokea,169:pokea+1,13:pokea+2,32
  147. 1460 pokea+3,210:pokea+4,255:a=a+5:return
  148. 1470 rem .. gosub/goto
  149. 1480 pokea,o:pokea+1,0:pokea+2,0:gosub400
  150. 1490 r=r+1:n(r)=n:a(r)=a:a=a+3:return
  151. 1500 rem .. for        
  152. 1510 u=831:gosub100
  153. 1520 lp=a:pokea,76:a=a+3
  154. 1530 hu=u:u=829:gosub40:u=hu+1
  155. 1540 pokea,133:pokea+1,34:pokea+2,134:pokea+3,35:a=a+4
  156. 1550 hf=f:w=177:gosub1090:f=hf
  157. 1560 pokea-1,3:pokea-3,2:pokea-9,11
  158. 1570 pokea-2,176:pokea-4,240
  159. 1580 xa=a:pokea,76:a=a+3
  160. 1590 ifpeek(u)<>169thenpokea,169:pokea+1,1:pokea+2,162:pokea+3,0:a=a+4:goto1610
  161. 1600 u=u+1:gosub100
  162. 1610 u=828:b=170:gosub150
  163. 1620 d=a:gosub570:pokelp+1,l:pokelp+2,h
  164. 1630 d=peek(829):gosub990:return
  165. 1640 rem .. next       
  166. 1650 d=lp+3:gosub570:pokea,76:pokea+1,l:pokea+2,h:a=a+3:d=a:gosub570
  167. 1660 pokexa+1,l:pokexa+2,h:return
  168. 1670 rem .. sys
  169. 1680 gosub100:pokea,133:pokea+1,20
  170. 1690 pokea+2,134:pokea+3,21
  171. 1700 pokea+4,32:pokea+5,54:pokea+6,225:a=a+7:return
  172. 1710 rem .. poke
  173. 1720 gosub100:pokea,133:pokea+1,34
  174. 1730 pokea+2,134:pokea+3,35:a=a+4
  175. 1740 ifpeek(u)<>44then920
  176. 1750 u=u+1:gosub100:pokea,160:pokea+1,0
  177. 1760 pokea+2,145:pokea+3,34:a=a+4:return
  178. 1770 rem .. init        
  179. 1780 dimn(63),a(63),s(255),l(255),t$(75)
  180. 1790 a=0:b=0:u=0:i=0:j=0:k=0:v=0:d=0
  181. 1800 c=0:h=0:l=0:w=0
  182. 1810 poke53281,0:poke53280,0:poke646,15
  183. 1820 s$="test.for":s=49152:z$=chr$(0)
  184. 1830 input"source name";s$
  185. 1840 restore:ifs$="*"thenend
  186. 1850 input"starting address";s:a=s+6
  187. 1860 d=a:gosub570:pokes,76:pokes+1,l:pokes+2,h
  188. 1870 pokes+3,76:pokes+4,116:pokes+5,164
  189. 1880 open15,8,15:open2,8,2,"0:"+s$
  190. 1890 input#15,e1,e2$,e3,e4:ife1=0thenreturn
  191. 1900 printe1;e2$;e3;e4
  192. 1910 rem .. finish      
  193. 1920 close2:close15
  194. 1930 ifr=0then1980
  195. 1940 fori=1tor:n=n(i):w=a(i):d=0
  196. 1950 fort=0tom:ifs(t)=nthend=l(t):t=m
  197. 1960 nextt:gosub570:pokew+1,l
  198. 1970 pokew+2,h:nexti
  199. 1980 ifg=0then2030
  200. 1990 d=a:gosub570:pokes+4,l:pokes+5,h
  201. 2000 readd:ifd<0then2030
  202. 2010 pokea,d:a=a+1
  203. 2020 goto2000
  204. 2030 pokea,0:e=a+1
  205. 2040 print"errors";er
  206. 2050 print"address range";s;"[157]";e*-1
  207. 2060 prints$;" compiled, time:";ti$
  208. 2070 print"1-save 2=exec 3=comp 4=quit":poke198,0
  209. 2080 getx$:ifx$="1"then2170
  210. 2090 ifx$="2"then2140
  211. 2100 ifx$="3"thengosub1820:goto590
  212. 2110 ifx$="4"thenend
  213. 2130 goto2080
  214. 2140 fori=680to731:pokei,0:next
  215. 2150 syss:goto2070
  216. 2160 rem .. save
  217. 2170 n$=s$+".ml":input"name";n$
  218. 2180 open15,8,15,"s0:"+n$:close15:t$=n$
  219. 2190 d=peek(53)+peek(54)*256-len(t$)
  220. 2200 poke782,d/256:poke781,d-peek(782)*256:poke780,len(t$):sys65469:poke780,1
  221. 2210 poke781,8:poke782,1:sys65466
  222. 2220 poke254,s/256:poke253,s-peek(254)*256:poke780,253:poke782,e/256
  223. 2230 poke781,e-peek(782)*256:sys65496
  224. 2240 if(peek(783)and1)or(st and191)thenprint"disk error"
  225. 2250 goto2070
  226. 2260 rem .. mul/div data     
  227. 2270 data133,99,134,100,162,0,134,101
  228. 2280 data134,102,160,16,144,34,6,97
  229. 2290 data38,98,38,101,38,102,56,165
  230. 2300 data101,229,99,170,165,102,229,100
  231. 2310 data144,6,134,101,133,102,230,97
  232. 2320 data136,208,227,165,97,166,98,96
  233. 2330 data70,102,102,101,102,98,102,97
  234. 2340 data136,48,240,144,243,24,165,101
  235. 2350 data101,99,133,101,165,102,101,100
  236. 2360 data133,102,24,144,227,-1
  237.